"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".

Replace this with more appropriate tests for your application.
"""

from django.test import TestCase
from frontend.models import *

class SimpleTest(TestCase):
    def test_insertToDB_and_getEmail(self):
        insertUserToDB("admin", "password", "huunam118@gmail.com")
        # Now table auth_user has a new row. 
        # Get Email of user whose username = "admin"
        self.assertEqual(getEmail("admin"), "huunam118@gmail.com")  # --> Passed testcase
        #self.assertEqual(getEmail("admin"), "admin1@storebook.com") # --> Failed testcase 
        #self.assertEqual(getEmail("admin"), "admin2@storebook.com")   
         
    def test_getFeaturedBook(self):
        rows = getFeaturedBook()
        print "----------------FeaturedBook-------------------"
        if rows:
            for i in rows:
                print i
        else:
            print "Failed ! No Featured Book Return"
            raise
        
    def test_getSpecialBook(self):
        rows = getSpecialBook()
        print "----------------SpecialBook-------------------"
        if rows:
            for i in rows:
                print i
        else:
            print "Failed ! No Special Book Return"
            raise
        
    def test_getAllBook(self):
        rows = getAllBook()
        print "------------AllBook----------------"
        if rows:
            for i in rows:
                print i
        else:
            print "Failed ! No Book Return"
            raise
    def test_getBookFromId(self):
        id = 22 # can add any number from 1->63 
        # faied if id = 21, 22, 23 ...
        # true if id = the others
        print "------------BookFromID----------------"
        rows = getBookFromId(id)
        if rows:
            self.assertEqual(rows[5], id)
        else:
            print "Failed ! No Book Return"
            raise
            
    def test_getRelatedBook(self):
        id = 22 # can add any number from 1->63 
        # faied if id = 21, 22, 23 ...
        # true if id = the others
        rows = getRelatedBook(id)
        print "----------------RelatedBook-------------------"
        if rows:
            for i in rows:
                print i
        else:
            print "Failed ! No book id = %d" % id
            raise
    def test_getNewBook(self):
        rows = getNewBook()
        print "----------------CategoryBook-------------------"
        if rows:
            for i in rows:
                print i
        else:
            print "Failed ! No Category Return"
            raise
    
    def test_getCategory(self):
        rows = getCategoryBook()
        print "----------------CategoryBook-------------------"
        if rows:
            for i in rows:
                print i
        else:
            print "Failed ! No Category Return"
            raise 
        
    def test_getFamousBook(self):
        rows = getFamousBook()
        print "----------------FamousBook-------------------"
        if rows:
            for i in rows:
                print i
        else:
            print "Failed ! No Famous Book Return"
            raise 
    
    
    
    ######################### NOTE ########################
    ## Orther Function can test from browser             ##
    #######################################################
    
    
